<!--
 * @Description: 
 * @Author: charles
 * @Date: 2021-07-13 09:20:15
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-08-08 15:56:31
<template>
   <!-- 头部 -->

   <template>
    <div class="header">
      <!-- 第一行 -->
      <div class="header_top">
        <!-- 容器居中显示 -->
        <div class="wrapper">
          <div class="left"></div>
          <div class="right"><a href="http://www.sxau.edu.cn/"><span style="color:#fff">学校主页</span></a></div>
        </div>
      </div>
      
      <!-- / 第一行 -->
      <!-- 第二行 -->
      <div class="header_main">
        <div class="wrapper">
          <div class="logo" @click="toHomeHandler">
            <img src="/resources/images/logo.png" alt="">
          </div>
          
        </div>
      </div>
      <!-- /第二行 -->
      <!-- /容器居中显示 -->
      <div class="nav">
        
		    <ul class="menu">
			    <li class="menu_item">
				    <a href="">首页</a>
		
			    </li>
          <li class="menu_item" v-for="a in categories" :key="a.id" >
				    <a  @click="toListHandler(a)">{{a.name}}</a>
				      <ul class="sub_menu">
					      <li v-for="b in a.children" :key="b.id" ><a @click="toListHandler(b)">{{b.name}}</a></li>
				      </ul>
			    </li>
		    </ul>
	    </div>
      </div>
    

    <!-- /头部 -->
</template>
<script>
import { get } from "../../utils/request";
export default {
  data() {
    return {
      categories: [],
    };
  },
  methods: {
    toListHandler(cItem) {
      // this.$router.go(0)
      // this.$router.query = cItem
      this.$router.replace({
        path: "/list",
        query: cItem,
      });
      this.$router.go(0);
    },
    toHomeHandler() {
      this.$router.push({ path: "/home" });
    },
    // 加载栏目信息
    loadCategories() {
      let url = "/index/category/findCategoryTree";
      get(url).then((resp) => {
        this.categories = resp.data;
      });
    },
  },
  created() {
    this.loadCategories();
  },
};
</script>
<style lang="scss" scoped>
// 头部样式
$color_primary: #028b39;
.header {
  text-align: center;
  background: url(/resources/images/navbg.png);
  widows: 100%;
  height: 195px;
  .header_top {
    & > .wrapper::after {
      display: block;
      content: "";
      clear: both;
    }

    .left,
    .right {
      line-height: 3em;
    }
    .left {
      float: left;
    }
    .right {
      float: right;
      margin-right: 80px;
    }
  }
  .header_main {
    padding: 0.5em 0;
    & > .wrapper {
      display: flex;
      justify-content: space-between;
      position: relative;
    }
    .logo {
      margin-left: 200px;
      cursor: pointer;
      img {
        width: 100%;
        height: 70px;
        vertical-align: middle;
      }
    }
  }
}

ul,
ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

a {
  text-decoration: none;
  color: #666;
}
.nav {
  margin-top: 25px;
  text-align: center;
  display: inline-block;
  vertical-align: middle;
  height: 70px;
  background-color: null;
}
.nav a {
  color: #fff;
  font-style: 微软雅黑;
}
.nav ul.menu::after {
  display: block;
  content: "";
  clear: both;
}
.nav ul.menu > li.menu_item {
  font-size: 18px;
  float: left;
  position: relative;
  width: 110px;
  height: 45px;
  text-align: center;
  cursor: pointer;
}
.nav ul.menu > li.menu_item:hover ul.sub_menu {
  display: block;
}
.nav ul.menu ul.sub_menu {
  font-size: 15px;
  display: none;
  position: absolute;
  background-color: #395585;
  margin-top: 20px;
  margin-left: 5px;
  width: 100px;
}
.nav ul.menu ul.sub_menu a {
  color: #fff;
  box-sizing: border-box;
}
.nav ul.menu ul.sub_menu > li:hover {
  background-color: null;
}
.nav ul.menu ul.sub_menu > li {
  margin-top: 5px;
  height: 35px;
}
</style>